<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // for await...of 语句会在异步或者同步可迭代对象上创建一个迭代循环
      // 循环异步对象
      function Gen(time) {
        return new Promise((resolve, reject) => {
          setTimeout(function() {
            resolve(time)
          }, time)
        })
      }
      // for of循环异步对象 for循环结束统一返回结果
      //for await of 异步对象执行结束返回  结合async使用
      async function test() {
        let arr = [Gen(2000), Gen(100), Gen(3000)]
        for await (let item of arr) {
          console.log(Date.now(), item)
        }
      }
      test()
    </script>
  </body>
</html>
